
/***********/
//去重
function unqiArray(arr, type) {
    var hash = {};
    arr = arr.reduce(function (item, next) {
        hash[next[type]] ? "" : (hash[next[type]] = true && item.push(next));
        return item;
    }, []);
    return arr;
};

//过滤相同标签的省份
var proviceCode = unqiArray(proviceCode,'label');

//获取省份
var provicesList = proviceCode.map((item) => {
    var obj = {}
    var citys = []
    //获取省份
    obj.areaId = item['value']
    obj.areaName = item['label']

    //获取城市
    var citylist = china.filter((item_c) => {
        return item.label == item_c.provice
    });
    citylist.forEach((item_d) => {
        var findCity = cityCode.findIndex((item_e) => {
            return item_d.city == item_e.label
        })
        if (findCity !== -1) {
            var cityItem = cityCode[findCity]
            citys.push({
                areaId: cityItem.value,
                areaName: cityItem.label
            })
        };
    })
    obj.cities = unqiArray(citys, 'areaId')

    //获取区域
    obj.cities.forEach(item_f => {
        var counties = []
        var areaList = china.filter(item_g => {
            return item_f.areaName == item_g.city
        })
        areaList.forEach(item_h => {
            var findArea = areaCode.findIndex(item_i => {
                return item_h.area == item_i.label
            })
            if (findArea !== -1) {
                var areaItem = areaCode[findArea]
                counties.push({
                    "areaId": areaItem.value,
                    "areaName": item_h.roomname,
                    "areaImg": `images/code/${item_h.managecode}.jpg`
                })
            }
        })
        item_f.counties = counties
    })

    return obj
})
var getProviceList = provicesList

console.log('获取数据------->', getProviceList);

// window.body.innertext = JSON.stringify(getProviceList)

console.log(JSON.stringify(getProviceList));

document.write(JSON.stringify(getProviceList))

//定义一个固定item格式
var hadJson = {
    "areaId": "1001",
    "areaName": "北京市",
    "cities": [
        {
            "areaId": "2001",
            "areaName": "北京市",
            "counties": [
                {
                    "areaId": "4001",
                    "areaName": "中国电鼓楼北街营业厅",
                    "areaImg": "images/code/30201.jpg"
                },
                {
                    "areaId": "4002",
                    "areaName": "中国电望京营业厅",
                    "areaImg": "images/code/30202.jpg"
                },
                {
                    "areaId": "4003",
                    "areaName": "中国电信黄村营业厅",
                    "areaImg": "images/code/30203.jpg"
                },
                {
                    "areaId": "4004",
                    "areaName": "中国电信西单营业厅",
                    "areaImg": "images/code/30204.jpg"
                }
            ]
        }
    ]
};


